using System;
using ProtoScratch.Common;

namespace TestSpace
{
	//A new instance of this class will be spawned for each individual connection. You can essentially
	//treat everything in this class as if you are dealing with a single connection only.
	//Note that all methods in this class will occur on their own thread, so ensure your actions are
	//thread safe
	public class ServerSample : ScratchEvents
	{
		//This event occurs when a new connection has arrived to the server and has been validated.
		public override void NewConnection()
		{
			Console.WriteLine("Server gained a connection");
		}
		
		//This event occurs when this connection to the server has been lost
		public override void ConnectionLost()
		{
			Console.WriteLine("Server lost a connection");
		}
		
		//We are implementing a ProtoScratch echo server here, so we simply send the same message back.
		//This event occurs when a new message is received from the client.
		public override void MessageReceived(ScratchMessage Message)
		{
			Console.WriteLine("Message Received");
			Send(Message); //echo...
		}
	}
}

